<?php

namespace App\Http\Controllers;

use App\Car;
use App\Owner;
use Illuminate\Http\Request;


class CarController extends Controller
{
    /**
     * @param Request $request
     * @return Car[]|\Illuminate\Database\Eloquent\Collection
     *
     */
    public function index(Request $request)
    {
        $car = new Car(
            [
                'name' => 'bmw'
            ]
        );
        $owner = new Owner(
            [
                'name' => 'zhang san'
            ]
        );
    
        $owner = Owner::create(
            [
                'name' => 'lis i '
            ]
        );
        $owner->save();
        $owner->cars()->save($car);
        $cars = Car::all('name');
//        dump(Car::count());
        return $cars;
    }
}
